/**
 * 
 */
package hu.gbalage.owl.editor.internal;

import hu.gbalage.owl.editor.OWLEditorManager;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.eclipse.swt.widgets.Composite;

/**
 * @author balage
 *
 */
public class OWLEditorRegistry implements Iterator<OWLEditorTab>, Iterable<OWLEditorTab>{

	public static String expoint = "hu.gbalage.owl.editor.tabs";
	
	private List<IConfigurationElement> elements = new ArrayList<IConfigurationElement>();
	
	private OWLEditorManager manager;
	
	private Composite parent;
	
	public OWLEditorRegistry(Composite parent, OWLEditorManager manager){
		this.manager = manager;
		this.parent = parent;
		IExtensionRegistry registry = Platform.getExtensionRegistry();  
		IExtensionPoint point = registry.getExtensionPoint(expoint);
		for (IExtension extension : point.getExtensions()){  
			for (IConfigurationElement element : extension.getConfigurationElements()){
				if (element.getName().equals("tab")) elements.add(element);
			}
		}
	}
	
	public boolean hasNext() {
		return !elements.isEmpty();
	}

	public OWLEditorTab next() {
		if (!hasNext()) return null;
		return new OWLEditorTab(parent,elements.remove(0),manager);
	}

	public void remove() {
		//can't remove
	}

	public Iterator<OWLEditorTab> iterator() {
		return this;
	}

}
